//
//  SinaBaseTableViewController.swift
//  weibo
//
//  Created by guyue on 15/12/30.
//  Copyright © 2015年 guyue. All rights reserved.
//

import UIKit

//一定要遵守这个协议 SinaVisitorViewDelegate
class SinaBaseTableViewController: UITableViewController,SinaVisitorViewDelegate {

    var isLogin: Bool = false
    
    var visitor: SinaVisitorView?
    
    //loadView 这个方法是创建视图的
    override func loadView() {
        if isLogin {
        
        //显示登录的视图
            super.loadView()
        
        }else {
        //显示访客视图
         
           //view = SinaVisitorView()
            
            visitor = SinaVisitorView()
            
            //调用动画
            visitor?.startAnimation()
            
            //设置代理
            visitor?.delegate = self
            
            //调用nav
            
            setupNav()
            
            //visitor.backgroundColor = UIColor.redColor()
            
            view = visitor
            
        
        }
    }
    
    //设置nav
    private func setupNav(){
        
        
       // UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //这个方法在这儿没有用
        
        //UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegisterMethod")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didLoginMethod")
    
    }
    
    //一定要实现代理方法,要不然就是报错
    
    func didLoginMethod() {
        
        printLog("base 登录")
    }
    func didRegisterMethod() {
        
        printLog("base 注册")
        
        //跳转到nav页面
        
        //创建控制器视图
        let oauth = SinaOauthViewController()
        
        //加到一个nav上面
        let nav = UINavigationController(rootViewController: oauth)
        
        //跳转
        presentViewController(nav, animated: true) { () -> Void in
        
        }
        
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
    }

}